var BSTMG = BSTMG || {};
BSTMG.accountMoneyManager = {
	init: function(){
		var that = this;
		//分页功能
		that.selectAccountMoneyList();
	},
	selectAccountMoneyList: function(){
		BSTMG.common.hjhPages('/accountMoney/accountMoneyList/search/',function(data){
			var userList = data.userList;
			var totalAccount = data.totalAccount;
			$('#totalAccount').text(parseFloat(totalAccount).toFixed(2));
			var recoveryAccount = data.recoveryAccount;
			$('#recoveryAccount').text(parseFloat(recoveryAccount).toFixed(2));
			var lineAccount = data.lineAccount;
			$('#lineAccount').text(parseFloat(lineAccount).toFixed(2));
			
			var $tbody = $("#accountMoneyList tbody");
			var $tr = '';
			if(userList.length > 0) {
				for(var i=0;i<userList.length;i++){
					var userInfo = userList[i];
					var loginNum = setLoginNum(userInfo);
					var accountMoney = setAccountMoney(userInfo);
					$tr += '<tr class="odd">';
					$tr += '<td>'+(i+1)+'</td>';
					$tr += '<td>'+checkNull(loginNum)+'</td>';
					$tr += '<td>'+checkNull(userInfo.belongCompanyName)+'</td>';
					$tr += '<td>'+parseFloat(accountMoney).toFixed(2)+'元</td>';
					$tr += '<td><a type="button" class="btn btn-primary" href="/accountMoney/userDealList/'+userInfo.userId+'">交易清单</a></td>';
					$tr += '</tr>';
				}
				$tbody.html($tr);
			}else {
				var $tr = '<tr class="odd"><td colspan="7">暂无数据！</td></tr>';
				$tbody.html($tr);
			}
		});
	}
}

$(function(){
	BSTMG.accountMoneyManager.init();
});

//检测非空
function checkNull(para){
	if(para == null){
		return "";
	}else{
		return para;
	}
}
function setAccountMoney(userInfo){
	if(userInfo.accountMoney != null ){
		return userInfo.accountMoney;
	}else{
		return 0.00;
	}
}
//设置登陆账号
function setLoginNum(userInfo){
	if(userInfo.userEmail != "" && userInfo.userEmail != null){
		return userInfo.userEmail;
	}else if(userInfo.userTel != "" && userInfo.userTel != null){
		return userInfo.userTel;
	}else{
		return "";
	}
}




